<template>
	<view>
		<view style="padding= 30rpx">异步接口</view>
		<button @click="callStorageFun(1)" type="primary">setStorage</button>
		<button @click="callStorageFun(2)" type="primary" plain="true">getStorage</button>
		<button @click="callStorageFun(3)" type="primary">setStorageInfo</button>
		<button @click="callStorageFun(4)" type="warn">removeStorage</button>
		<button @click="callStorageFun(5)" type="warn" plain="true">clearStorage</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				name:'qiuhanle',
				timer1:null
			}
		},
		methods: {
			callStorageFun(parm){
				console.log("callStoragrFun ==> parm " +parm);
				switch(parm){
					case 1 :
					// 存一个字段到本地 字段名 值
					uni.setStorage({
						key:'className',
						data:'23计本',
						success(){
							console.log("UserName 存储成功");
						}
					});
					console.log("调用存储完成 ");
					break;
					case2:
					uni.getStorage({
						key:'UserName',
						// 回调接口
						success:function(result){
							console.log("读取UserName成功 result.data=" +result.data);
						},
						fail(){
							console.log("读取UserName失败");
						}
					});
					break;
					case 3:
					uni.getStorageInfo({
						success:function(result){
							console.log("获取所有缓存字段 :" +result.keys);
						}
					})
					break;
					case 4:
					uni.removeStorage({
						key:'UserName',
						success(){
						console.log("删除userName成功 " );	
						}
					})
					break
				}
			}
			
		}
	}
</script>

<style>

</style>
